﻿using System.Collections.Specialized;
using System.Web.Mvc;
using Xoohoo.Extensions;
using Xoohoo.Modules.Admin.Models;

namespace Xoohoo.Modules.Admin.ModelBinders
{
    public class UserChangePasswordInputModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;

            string currentPassword = valueProvider.GetAttemptedValue("currentPassword");
            string newPassword = valueProvider.GetAttemptedValue("newPassword");
            string newPasswordConfirm = valueProvider.GetAttemptedValue("newPasswordConfirm");

            return new UserChangePasswordInput
            {
                CurrentPassword = currentPassword
                ,NewPassword = newPassword
                ,NewPasswordConfirm = newPasswordConfirm
            };
        }
    }
}
